#include <openssl/sm3.h>
#include <openssl/hmac.h>
#include <stdio.h>
#include <string.h>

void sm3_digest() {
    unsigned char digest[SM3_DIGEST_LENGTH];
    const char *message = "Hello, SM3!";
    
    SM3((unsigned char *)message, strlen(message), digest);
    
    printf("SM3 Digest: ");
    for (int i = 0; i < SM3_DIGEST_LENGTH; i++) {
        printf("%02x", digest[i]);
    }
    printf("\n");
}

void sm3_hmac() {
    const char *key = "mysecretkey";
    const char *data = "Hello, HMAC with SM3!";
    unsigned char hmac[SM3_DIGEST_LENGTH];
    
    unsigned int len = 0;
    HMAC(EVP_sm3(), key, strlen(key), (unsigned char *)data, strlen(data), hmac, &len);
    
    printf("SM3 HMAC: ");
    for (int i = 0; i < len; i++) {
        printf("%02x", hmac[i]);
    }
    printf("\n");
}

int main() {
    sm3_digest();
    sm3_hmac();
    return 0;
}

